<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
    

<div class="modal-dialog demo2do-modal-dialog">

  <div class="modal-content">

    <div class="modal-header earth-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>补充风险保证金</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" class ="form-horizontal"  data-validate ="true">

      <input type="hidden" name="chargeId" value="${chargeId }" id="chargeId" >

      <div class="modal-body">

		     <div class="form-group demo2do-form-group">
		       
		       <label class="col-xs-4 control-label">保理合同编号</label>
		         <div class="col-xs-5">
		              <select class="form-control" name="factoringContractId" id="factoringContractId" <c:if test="${charge.chargeStatus.ordinal() == 1 }">disabled="disabled"</c:if>>
		                 <c:forEach var="factoringContract" items="${factoringContractList }">
		                   <option value=${factoringContract.id } <c:if test="${charge.factoringContractId eq factoringContract.id}">selected="selected"</c:if> >${factoringContract.contractNo }</option>
		                 </c:forEach>
		              </select>                        
		         </div>               
		
		     </div>
		     
          <div class="form-group demo2do-form-group">
          
            <label class="col-xs-4 control-label">批次号</label>
    
            <div class="col-xs-5">
              <input type="text" class="form-control" name="batchNo" id="batchNo" value="${charge.batchNo }" <c:if test="${charge.chargeStatus.ordinal() == 1 }">disabled="disabled"</c:if>/>
            </div>
    
          </div>  		     
		
		      <div class="form-group demo2do-form-group">
		      
		         <label class="col-xs-4 control-label">金额</label>
		         <div class="col-xs-5">
		           <div class="input-group">
		             <input type="text" name="amount" id="amount" class="form-control" required="required" value="${charge.payMoney }" <c:if test="${charge.chargeStatus.ordinal() == 1 }">disabled="disabled"</c:if>/>
		             <span class="input-group-addon">元</span>
		           </div>
		         </div>
		
		      </div> 
		
		   
		      <div class="form-group demo2do-form-group">
		      
		        <label class="col-xs-4 control-label">备注</label>
		
		        <div class="col-xs-5">
		          <input type="text" class="form-control" name="remark" id="remark" value="${charge.remark }" />
		        </div>
		
		      </div>    

      </div>

      <div class="modal-footer">
          <button type="button" class="btn btn-success btn-shadow btn-shadow-success demo2do-btn" id="deductBtn" <c:if test="${charge.chargeStatus.ordinal() == 1 }">disabled="disabled"</c:if> >扣款</button>&nbsp;&nbsp;&nbsp;&nbsp;
          <button type="button" class="btn btn-success btn-shadow btn-shadow-success demo2do-btn" id="payBtn" <c:if test="${ charge eq null || charge.chargeStatus.ordinal() == 0 }">disabled="disabled"</c:if> >打款</button>
      </div>

    </form>

  </div>

</div>

   <script type="text/javascript">
  
     $("#deductBtn").click(function(){
        $('#deductBtn').attr('disabled',"true");
        $('#deductBtn').html("扣款中。。。");
        var chargeId = $("#chargeId").val();
        var factoringContractId = $("#factoringContractId").val();
        var batchNo = $("#batchNo").val();
        var amount =  $("#amount").val();
        var remark = $("#remark").val();
        $.ajax({
  
          type:'POST',
             url:'${ctx}/riskbail/dodeduct',
             data:{'chargeId':chargeId,'factoringContractId':factoringContractId,'batchNo':batchNo,'amount':amount,'remark':remark},
             dataType: 'json',
             error: function(){
                 alert('网络错误！稍后再试！');
                 $('#deductBtn').removeAttr("disabled");
                 $('#deductBtn').html("扣款");
             },
             success:function(data){
                 
               $('#dialog').find('.modal-body p').text(data.message).end().modal();
               
             }
        });
    }); 
  </script>
  <script type="text/javascript">
  $("#payBtn").click(function(){
      $('#payBtn').attr('disabled',"true");
      $('#payBtn').html("打款中。。。");
      var chargeId = $("#chargeId").val();
      $.ajax({

        type:'POST',
           url:'${ctx}/riskbail/dopay',
           data:{'chargeId':chargeId},
           dataType: 'json',
           error: function(){
               alert('网络错误！稍后再试！');
               $('#payBtn').removeAttr("disabled");
               $('#payBtn').html("打款");
           },
           success:function(data){
               
               $('#dialog').find('.modal-body p').text(data.message).end().modal();
               
           }
      });
  });
</script>

<script>
    $("#closeBtn").bind("click", function(){
      window.location.href = "${ctx}/riskbail/list";
    });
</script>

<div class="modal fade" id="dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">提示</h4>
      </div>
      <div class="modal-body">
        <p></p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeBtn">关闭</button>
      </div>
    </div>
  </div>
</div>
